package name.huzhenbo.java.patterns.singleton;

/**
 * safe and lazy initialization.
 */
class InitiOnDemandSingleton {
    private int creationCount = 0;

    private InitiOnDemandSingleton() {
        creationCount++;
    }

    public static InitiOnDemandSingleton getInstance() {
        return SingletonHolder.INSTANCE;
    }

    public int getCreationCount() {
        return creationCount;
    }

    /**
     * Initilize on demand holder: a class will not initializ until it is used.
     */
    private static class SingletonHolder {
        // be final
        static final InitiOnDemandSingleton INSTANCE = new InitiOnDemandSingleton();
    }
}
